import { defineStore } from 'pinia';
import { ref } from 'vue';

/**
 * 主题枚举
 * @param LIGHT 亮色主题
 * @param DARK 暗色主题
 */
export enum ThemeEnum {
  LIGHT = 'light', // 亮色主题
  DARK = 'dark', // 暗色主题
}

export default defineStore('app', () => {
  const state = ref({
    title: 'Vite Vue 3 admin',
  });

  const config = ref({
    collapsed: false,
    theme: ThemeEnum.LIGHT, // 主题 light dark
  });

  // 设置标题
  const setTitle = (title: string) => {
    state.value.title = title;
  };

  // 设置侧边栏折叠状态
  const setCollapsed = (collapsed: boolean) => {
    config.value.collapsed = collapsed;
  };
  // 改变侧边栏折叠状态
  const toggleCollapsed = () => {
    config.value.collapsed = !config.value.collapsed;
  };

  // 设置主题
  const setTheme = (theme: ThemeEnum) => {
    config.value.theme = theme;
  };

  return { state, setTitle, config, setCollapsed, toggleCollapsed, setTheme };
});
